{% extends 'base_templates/_page_layout.html' %}

{% block css %}
    <!-- DataTables -->
    <link href="/static/plugins/minton/plugins/datatables/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css">
    <link href="/static/plugins/minton/plugins/datatables/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css">

    <!-- Responsive datatable examples -->
    <link href="/static/plugins/minton/plugins/datatables/responsive.bootstrap4.min.css" rel="stylesheet" type="text/css">
    <style>
    </style>
{% endblock %}

{% block title %}

    <!-- Page-Title -->
    <div class="row">
        <div class="col-sm-12">
            <div class="page-title-box">
                <h4 class="page-title">用户信息</h4>
                <ol class="breadcrumb float-right">
                    <li class="breadcrumb-item"><a href="/system/user/{{obj.id}}/change">{{obj.name}}</a></li>
                    <li class="breadcrumb-item"><a href="/system/user/list">用户信息</a></li>
                    <li class="breadcrumb-item active">Dashboard</li>
                </ol>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>

{% endblock %}

{% block conent %}


<!-- sample modal content -->
<div id="aEditPassword" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="CenterModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <form role="form" action="/system/user/update/password/{{ obj.id }}" method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <label class="modal-title" id="CenterModalLabel">Edit Password</label>
                </div>
                <div class="modal-body">

                    <p class="text-muted m-b-30 font-14">
                        修改 <code>{{ form_userPassword_obj.instance }}</code> password.
                    </p>
                    <div class="form-group">
                        <label for="Password">Password</label>
                        {{ form_userPassword_obj.password1 }}
                        <span style="color: red">{{ form_userPassword_obj.errors.password1 }}</span>
                    </div>
                    
                    <div class="form-group">
                        <label for="RePassword">Re-Password</label>
                        {{ form_userPassword_obj.password2 }}
                        <span style="color: red">{{ form_userPassword_obj.errors.password2 }}</span>
                    </div>

                </div>
                <div class="modal-footer">

                    <button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary waves-effect waves-light">Save changes</button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<div class="row">
    <div class="col-12">
        <div class="card-box">
            <h4 class="m-t-0 header-title">编辑用户</h4>
            <p class="text-muted m-b-30 font-14">
                编辑用户 <code>{{ obj.name }}</code> .
            </p>
            <div class="row">
                <div class="col-lg-12">
                    <div class="card-box">
                        <form class="" action="#" novalidate="" method="post">
                            <div class="form-group">
                                <label>Email:</label><a class="pull-right" href="#" data-toggle="modal" data-target="#aEditPassword">Edit Password</a>
                                {{ form_userInfo_obj.email }}
                                <span style="color: red">{{ form_userInfo_obj.errors.email }}</span>
                            </div>

                            <div class="form-group">
                                <label>姓名:</label>
                                {{ form_userInfo_obj.name }}
                                <span style="color: red">{{ form_userInfo_obj.errors.name }}</span>
                            </div>

                            <div class="form-group">
                                <label>电话:</label>
                                {{ form_userInfo_obj.phone }}
                                <span style="color: red">{{ form_userInfo_obj.errors.phone }}</span>
                            </div>

                            <div class="form-group">
                                <label>国家:</label>
                                {{ form_userInfo_obj.location }}
                                <span style="color: red">{{ form_userInfo_obj.errors.location }}</span>
                            </div>                            
                            <div class="form-group">
                                <label>活跃用户:</label>
                                {{ form_userInfo_obj.is_active }}
                                <span style="color: red">{{ form_userInfo_obj.errors.is_active }}</span>
                            </div>                            
                            <div class="form-group">
                                <label>管理员:</label>
                                {{ form_userInfo_obj.is_staff }}
                                <span style="color: red">{{ form_userInfo_obj.errors.is_staff }}</span>
                            </div>

                            <div class="form-group">
                                <label>加入的 Role:</label>
                                <p class="text-muted m-b-15 font-13">
                                    左边为   
                                    <code>&lt; Role &gt;</code>
                                    列表，如果想加入到该 
                                    <code>&lt; Role &gt;</code>
                                    中，请移动到右边.
                                </p>
                                {{ form_userInfo_obj.groups }}
                                <span style="color: red">{{ form_userInfo_obj.errors.groups }}</span>
                            </div>

                            {# <div class="form-group"> #}
                                {# <label>活跃用户:</label> #}
                                {# {{ form_obj.is_active }} #}
                                {# <span style="color: red">{{ form_obj.errors.is_active }}</span> #}
                            {# </div> #}


                            <div class="form-group col-md-12">
                                <div class="form-group mx-sm-3 text-right">
                                    </span></button>
                                    <button class="btn btn-primary waves-effect waves-light"> <span>Save Info</span></button>
                                </div>
                            </div>
                        </form>
                        <div class="form-group col-md-12">
                            <div class="form-group mx-sm-3 text-right">
                                <button id="btnDeleteUser" class="btn btn-danger"><i class="fa fa-times"></i> <span>Delete</span></button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

    </div><!-- end col -->
</div>
{% endblock %}

{% block js %}
<!-- Selection table -->
<script src="/static/plugins/minton/plugins/datatables/dataTables.select.min.js"></script>
<script src="/static/plugins/minton/plugins/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script>
<script type="text/javascript" src="/static/plugins/minton/plugins/multiselect/js/jquery.multi-select.js"></script>
<script type="text/javascript" src="/static/plugins/minton/plugins/jquery-quicksearch/jquery.quicksearch.js"></script>
<script src="/static/plugins/minton/plugins/select2/js/select2.min.js" type="text/javascript"></script>
<script src="/static/plugins/minton/plugins/bootstrap-touchspin/dist/jquery.bootstrap-touchspin.min.js" type="text/javascript"></script>
<script src="/static/plugins/minton/plugins/bootstrap-inputmask/bootstrap-inputmask.min.js" type="text/javascript"></script>

<script src="/static/plugins/minton/plugins/moment/moment.js"></script>
<script src="/static/plugins/minton/plugins/mjolnic-bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js"></script>
<script src="/static/plugins/minton/plugins/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script src="/static/plugins/minton/plugins/bootstrap-daterangepicker/daterangepicker.js"></script>

<script src="/static/plugins/minton/pages/jquery.form-advanced.init.js"></script>
<script src="/static/plugins/minton/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="/static/plugins/minton/plugins/datatables/dataTables.bootstrap4.min.js"></script>

<!-- Key Tables -->
<script src="/static/plugins/minton/plugins/datatables/dataTables.keyTable.min.js"></script>

<!-- Responsive examples -->
<script src="/static/plugins/minton/plugins/datatables/dataTables.responsive.min.js"></script>
<script src="/static/plugins/minton/plugins/datatables/responsive.bootstrap4.min.js"></script>

<!-- Selection table -->
<script src="/static/plugins/minton/plugins/datatables/dataTables.select.min.js"></script>

<!-- Required datatable js -->
<script src="/static/plugins/minton/plugins/datatables/jquery.dataTables.min.js"></script>
<script>
    jQuery(document).ready(function () {

        $('.summernote').summernote({
            height: 250,                 // set editor height
            minHeight: null,             // set minimum height of editor
            maxHeight: null,             // set maximum height of editor
            focus: false                 // set focus to editable area after initializing summernote
        });
    });
    $(function(){
        bindDeleteUser();
    });
    function bindDeleteUser(){

        $("#btnDeleteUser").click(function(){
            var postData = {};
            var DELETEDATA = "UserList"
            postData[DELETEDATA] = ["{{ obj.id }}"];
            
            
            if (!jQuery.isEmptyObject(postData[DELETEDATA])){
                swal({
                    title: '你确定要删除？',
                    text: "点击确定后会进行删除！",
                    type: 'question', // warning
                    showCancelButton: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    confirmButtonClass: 'btn btn-success mt-2 delete-resume-source',
                    cancelButtonClass: 'btn btn-danger ml-2 mt-2',
                    buttonsStyling: false
                }).then(function () {
                    
                }, function (dismiss) {
                    if (dismiss === 'cancel') {
                        swal({
                            title: '已取消',
                            text: "成功取消删除操作!",
                            type: 'success',
                            confirmButtonClass: 'btn btn-confirm mt-2'
                        })
                    }
                });
                $('.delete-resume-source').click(function () {
                    postData[DELETEDATA] = JSON.stringify(postData[DELETEDATA])
                    DeleteData(postData);
                })
            }else {
                $.Notification.autoHideNotify('error', 'top right', '无效的删除','无效的操作，没有需要删除的数据，请查看后再次删除!')
            }
            
        })
    }
    function DeleteData(postData){
        $.ajax({
            url: '/system/user/delete',
            data: postData,
            type: 'POST',
            dataType: "JSON",
            success: function(arg){
                if (arg.status_code != "200"){
                    swal({
                        title: '错误',
                        text: "数据删除失败!",
                        type: 'error',
                        confirmButtonClass: 'btn btn-confirm mt-2'
                    })
                }else{
                    swal({
                        title: '已删除',
                        text: "数据删除成功!",
                        type: 'success',
                        confirmButtonClass: 'btn btn-confirm mt-2'
                    }).then(function () {
                        window.location.href="/system/user/list";
                    });
                    
                }
            }
        })
    }
</script>
{% endblock %}